@extends('Layouts.iframe')
<style>
    .select{
        width: 70%;
    }
    #myform{
        line-height: 3;
    }

</style>
@section('content')

    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 渠道管理 <span class="c-gray en">&gt;</span> 渠道用户列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="page-container">
        @if(auth()->user()->can('manager.search') or auth()->user()->can('manager.export'))
        <div class="text-l">
            <form action="{{route('manager.index')}}" method="get" id="myform">
                <div class="text-c">
                    <div class="col-sm-3">
                    用户号码 ：<input type="text" name="phone" value="{{$managers->phone}}" placeholder=" 用户号码" style="width:70%" class="input-text">
                    </div>
                    <div class="col-sm-3">
                    用户姓名 ：<input type="text" name="name"  value="{{$managers->name}}" placeholder=" 用户姓名" style="width:70%" class="input-text">
                    </div>
                    <div class="col-sm-3">
                        <label for="">渠道类型 : </label><span class="select-box inline">
                    <select name="type" class="select" style="width: 215px !important; height: 29px">
                        @if($managers->type == 0)
                            <option value="0" selected>不限</option>
                        @else
                            <option value="0">不限</option>
                        @endif
                            @if($managers->type == 1)
                                <option value="1" selected>公司</option>
                            @else
                                <option value="1">公司</option>
                            @endif
                            @if($managers->type == 2)
                                <option value="2" selected>个人</option>
                            @else
                                <option value="2">个人</option>
                            @endif

                    </select>
                    </span>
                    </div>
                    <div class="col-sm-3">
                    公司名称 ：<input type="text" name="company" value="{{$managers->company}}" id="" placeholder=" 公司名称" style="width:70%" class="input-text">
                    </div>
                    <div class="col-sm-3">
                    邀请码 ：<input type="text" name="invitation_code" value="{{$managers->invitation_code}}" id="" placeholder=" 邀请码" style="width:70%" class="input-text">
                    </div>
                    <div class="col-sm-3">
                    注册时间 ：
                                <input type="text"  onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'logmax\')||\'%y-%M-%d\'}' })" id="logmin" class="input-text Wdate" name="create_time_start" style="width:30%;" value="{{$managers->create_time_start}}">
                                -
                                <input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'logmin\')}',maxDate:'%y-%M-%d' })" id="logmax" class="input-text Wdate" name="create_time_end" style="width:30%;" value="{{$managers->create_time_end}}">
                    </div>
                    <div class="col-sm-3">
                    用户状态：<span class="select-box inline">
                    <select name="status" class="select" style="width: 215px !important; height: 29px">
                        @if($managers->status == 0)
                            <option value="0" selected>不限</option>
                        @else
                            <option value="0">不限</option>
                        @endif
                            @if($managers->status == 1)
                                <option value="1" selected>正常</option>
                            @else
                                <option value="1">正常</option>
                            @endif
                            @if($managers->status == 2)
                                <option value="2" selected>冻结中</option>
                            @else
                                <option value="2">冻结中</option>
                            @endif

                    </select>
                    </span>
                    </div>
                    <div class="col-sm-3">
                        @can('manager.search')
                        <button  id="submit" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
                        @endcan
                        @can('manager.export')
                        <span   class="btn btn-success" onclick="userExcel()"> 导出Excel</span>
                        @endcan
                    </div>
                </div>
            </form>
        </div>
        @endif
        <div class="cl pd-5  mt-20">
            {{--<span class="r">
                <a class="btn btn-primary radius" onclick="" href="javascript:;">
                    <i class="Hui-iconfont">&#xe600;</i>新增机构
                </a>
            </span>--}}
        </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-bg table-hover table-sort table-responsive">
                <thead>
                <tr class="text-c">
                    <th width="25"><input type="checkbox" name="" value=""></th>
                    <th width="80">ID</th>
                    <th width="80">用户号码</th>
                    <th width="80">用户姓名</th>
                    <th width="80">渠道类型</th>
                    <th width="120">公司名称</th>
                    <th width="75">邀请码</th>
                    <th width="100">注册时间</th>
                    <th width="60">状态</th>
                    {{--@if(auth()->user()->can('manager.free') or auth()->user()->can('manager.reset') or auth()->user()->can('manager.delete'))--}}
                    <th width="150">操作</th>
                        {{--@endif--}}
                </tr>
                </thead>
                <tbody>
                @if($managers->count())
                    @foreach($managers as $manager)
                <tr class="text-c">
                    <td><input type="checkbox" value="{{$manager->id}}" name=""></td>
                    <td>{{$manager->id}}</td>
                    <td>{{$manager->phone}}</td>
                    <td>{{$manager->name}}</td>
                    <td>
                        @if($manager->type==1)
                            公司
                            @elseif($manager->type==2)
                            个人
                            @endif
                    </td>
                    <td>{{$manager->company}}</td>
                    <td>{{$manager->invitation_code}}</td>
                    <td>{{$manager->created_at}}</td>
                    @if($manager->status==1)
                        <td class="td-status"><span class="label label-success radius">正常</span></td>
                        @elseif($manager->status==2)
                        <td class="td-status"><span class="label label-defaunt radius">冻结中</span></td>
                        @endif


                    <td class="f-14 td-manage">
                        @can('manager.free')
                        @if($manager->status==2)
                            <a style="text-decoration:none" onClick="free(this,'{{$manager->id}}')" href="javascript:;" title="解冻" class="label label-secondary  radius">解冻</a>

                        @else
                            <a style="text-decoration:none" onClick="freeze(this,'{{$manager->id}}')" href="javascript:;" title="冻结" class="label label-warning   radius">冻结</a>
                        @endif
                        @endcan()
                            @can('manager.reset')
                        <a style="text-decoration:none" class="ml-5 label label-secondary radius" onClick="pwdReset('重置密码','{{$manager->id}}')" href="javascript:;" title="重置密码">重置密码</a>
                            @endcan
                            @can('manager.delete')
                        <a style="text-decoration:none" class="ml-5 label label-danger radius" onClick="manager_del(this,'{{$manager->id}}')" href="javascript:;" title="删除" >删除</a></td>
                            @endcan
                </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
            <div id="pull_right">
                <div class="pull-right">
                    {!! $managers->render() !!}
                </div>
            </div>
        </div>
    </div>
@endsection
@section('js')
    <script type="text/javascript" src="/js/lib/WdatePicker.js"></script>
    <script type="text/javascript" src="/js/lib/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="/js/lib/laypage.js"></script>
    <script>
        function freeze(obj,id) {
            layer.confirm('确认冻结？冻结后无法登录',function(index){
                $.ajax({
                    type: 'post',
                    {{--url: '{{route('manager.update',['id'=>'1'])}}',--}}
                    url: '/admin/manager/'+id,
                    dataType: 'json',
                    data:{free:'freeze',_token: '{{ csrf_token() }}',_method:'PUT'},
                    success: function(data){
                        // $(obj).parents("tr").remove();
                        // layer.msg('已删除!',{icon:1,time:1000});
                        if(data.code == 0){
                            // layer.msg('已冻结!',{icon:1,time:1000});
                            layer.msg('已冻结！', {
                                icon: 1,
                                time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            }, function(){
                                location.replace(location.href);
                            });

                        }else{
                            layer.msg(data.message, {
                                icon: 1,
                                time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            }, function(){
                                location.replace(location.href);
                            });
                        }
                    },
                    error:function(data) {
                        console.log(data.msg);
                    },
                });
            });
        }
        function free(obj,id) {
            layer.confirm('确认冻结？冻结后无法登录',function(index){
                $.ajax({
                    type: 'post',
                    {{--url: '{{route('manager.update',['id'=>'1'])}}',--}}
                    url: '/admin/manager/'+id,
                    dataType: 'json',
                    data:{free:'free',_token: '{{ csrf_token() }}',_method:'PUT'},
                    success: function(data){
                        // $(obj).parents("tr").remove();
                        // layer.msg('已删除!',{icon:1,time:1000});
                        if(data.code == 0){

                            // layer.msg('已冻结!',{icon:1,time:1000});
                            layer.msg('成功解冻！', {
                                icon: 1,
                                time: 1000 //2秒关闭（如果不配置，默认是3秒）
                            }, function(){
                                location.replace(location.href);
                            });

                        }else{
                            layer.msg(data.message, {
                                icon: 1,
                                time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            }, function(){
                                location.replace(location.href);
                            });
                        }
                    },
                    error:function(data) {
                        console.log(data.msg);
                    },
                });
            });
        }

        function manager_del(obj,id) {
            layer.confirm('确认删除？删除后无法恢复',function(index){
                $.ajax({
                    type: 'post',
                    {{--url: '{{route('manager.update',['id'=>'1'])}}',--}}
                    url: '/admin/manager/'+id,
                    dataType: 'json',
                    data:{free:'manager_del',_token: '{{ csrf_token() }}',_method:'PUT'},
                    success: function(data){
                        // $(obj).parents("tr").remove();
                        // layer.msg('已删除!',{icon:1,time:1000});
                        if(data.code == 0){
                            // layer.msg('已冻结!',{icon:1,time:1000});
                            layer.msg('已删除！', {
                                icon: 1,
                                time: 1000 //2秒关闭（如果不配置，默认是3秒）
                            }, function(){
                                location.replace(location.href);
                            });
                        }else{
                            layer.msg(data.message, {
                                icon: 1,
                                time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            }, function(){
                                location.replace(location.href);
                            });
                        }
                    },
                    error:function(data) {
                        console.log(data.msg);
                    },
                });
            });
        }

        function pwdReset(obj,id) {
            layer.confirm('重置密码后，密码为该账号手机号码后6位',function(index){
                $.ajax({
                    type: 'post',
                    url: '{{ url('admin/manager/passwordReset') }}',
                    dataType: 'json',
                    data:{id:id,_token: '{{ csrf_token() }}'},
                    success: function(data){
                        if(data.code == 0){
                            layer.msg('重置成功！', {
                                icon: 1,
                                time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            }, function(){
                                location.replace(location.href);
                            });
                        }else{
                            layer.msg(data.message, {
                                icon: 2,
                                time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            }, function(){
                                location.replace(location.href);
                            });
                        }
                    },
                    error:function(data) {
                        console.log(data.msg);
                    },
                });
            });
        }
        function userExcel(){
            layer.msg('默认导出全部数据，需要指定行请勾选',{icon:1,time:3000});
            var groupCheckbox=$("input[type='checkbox']");
            var val = '';
            for(i=0;i<groupCheckbox.length;i++){
                if(groupCheckbox[i].checked){
                    if(groupCheckbox[i].value) {
                        val += ',' + groupCheckbox[i].value;
                    }
                }
            }
            if (val.substr(0,1)==',') val=val.substr(1);
            if(val.length > 0) {
                window.location.href = '/admin/manager/export/'+val;
            }else{
                window.location.href = '/admin/manager/export/all';
            }
        }
    </script>
@endsection